/**
 * 
 */
package org.oyrm.kobo.formBuilder.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.HeadlessException;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

import org.oyrm.kobo.formBuilder.controller.FormBuilderController;
import org.oyrm.kobo.formBuilder.settings.Settings;

/**
 * @author etherton
 *
 * This is an attempt to take the web based UI of the KoboOpenRosa project
 * and create a desktop app.
 */
public class DesktopFormBuilderFrame extends JFrame 
{

	/********************************************************************
	 * declare class variables
	 ********************************************************************/
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 6777262850949670294L;

	
	/**
	 * Menu Bar object
	 */
	private MainMenuBar menuBar = null;
	
	/**
	 * File Tool Bar object
	 */
	private MainToolBar fileToolBar = null;
	
	/**
	 * Questions Tool Bar object
	 */
	private QuestionsToolBar questionToolBar = null;
	
	/**
	 * Panel to hold all the tool bars 
	 */
	private JPanel toolBarPanel = null;
	
	/**
	 * Split pain to separate the question heirchy from individual question details
	 */
	private JSplitPane splitPane = null;
	
	/**
	 * The pane that holds the tree
	 */
	private JScrollPane treePane = null;

	/**
	 * The scroll pane that holds the center pane
	 */
	private JScrollPane centerScrollPane = null;
	
	/**
	 * The panel that holds the center
	 */
	private CenterPanel centerPanel = null;
	
	/**
	 * Status bar
	 */
	private StatusBar statusBar = null;
	
	/**
	 * Tree view for a view of all the parts of the form in question
	 */
	private LeftPanel leftPanel = null;
	
	/**
	 * The controller for stuff
	 */
	private FormBuilderController controller = null;
	
	/********************************************************************
	 * Methods for DesktopFormBuilderFrame
	 ********************************************************************/
	
	/**
	 * Constructor to get the ball rolling
	 * @throws HeadlessException
	 */
	public DesktopFormBuilderFrame() throws HeadlessException {
		super(Settings.getI18n().getString("mainTitle"));
		createComponents();
		placeComponents();
		
		this.pack();
		this.setMinimumSize(new Dimension(800,600));
		this.setVisible(true);
	}

	/**
	 * This method will create and initialize the components
	 * that make up this frame
	 */
	private void createComponents() {
						
		JLabel testLabel = new JLabel("What up?");
		centerPanel = new CenterPanel();
		centerPanel.add(testLabel);
		
		centerScrollPane = new JScrollPane(centerPanel);
		
		
		
		
		//Object[] array = {"hey", "hello", "what's up"};
		leftPanel = new LeftPanel();
		
		treePane = new JScrollPane(leftPanel);		
		
		splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
		splitPane.setOneTouchExpandable(true);
		splitPane.setDividerLocation(200);
		
		
		
		statusBar = new StatusBar();
		statusBar.setStatusText(Settings.getI18n().getString("statusBarGreeting"));
		
		//setup the controller that directs the actions into changes
		controller = new FormBuilderController(leftPanel, centerPanel, this);
		
		menuBar = new MainMenuBar(controller);
		
		controller.setMenuBar(menuBar);
		
		fileToolBar = new MainToolBar(controller);
		
		questionToolBar = new QuestionsToolBar();
		
		toolBarPanel = new JPanel();
		toolBarPanel.setLayout(new BoxLayout(toolBarPanel, BoxLayout.Y_AXIS));
		
	}
	
	
	/**
	 * This takes the components that make up this frame and puts
	 * them all together
	 */
	private void placeComponents() {
		
		setJMenuBar(menuBar);
		
		toolBarPanel.add(fileToolBar);
		toolBarPanel.add(questionToolBar);
		add(toolBarPanel, BorderLayout.NORTH);
		
			
		splitPane.setLeftComponent(treePane);
		splitPane.setRightComponent(centerScrollPane);
		
		add(splitPane, BorderLayout.CENTER);
		
		add(statusBar, BorderLayout.SOUTH);
	}







	/**
	 * Where it all starts
	 * @param args
	 */
	public static void main(String[] args) 
	{
		Settings.init();
		DesktopFormBuilderFrame fbApp = new DesktopFormBuilderFrame();
		fbApp.setVisible(true);

	}

}
